From 72e7d86389e136d36e90da9c827c1be516efd398 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 14 Dec 2014 00:25:21 +0000 Subject: [PATCH] Make gpx_version a QString in gpx writer. --- gpsbabel/gpx.cc | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 6e0528c3f..4d76be645 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -1,7 +1,7 @@ /* Access GPX data files. - Copyright (C) 2002-2013 Robert Lipe, gpsbabel.org + Copyright (C) 2002-2014 Robert Lipe, gpsbabel.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -44,7 +44,8 @@ static char* opt_humminbirdext = NULL; static char* opt_garminext = NULL; static int logpoint_ct = 0; -static char* gpx_version = NULL; +// static char* gpx_version = NULL; +QString gpx_version; static char* gpx_wversion; static int gpx_wversion_num; static QXmlStreamAttributes gpx_namespace_attribute; @@ -449,11 +450,10 @@ tag_gpx(const QXmlStreamAttributes& attr) /* Set the default output version to the highest input * version. */ - if (! gpx_version) { - gpx_version = xstrdup(attr.value("version").toString()); - } else if ((strtod(gpx_version, NULL) * 10) < (attr.value("version").toString().toDouble() * 10)) { - xfree(gpx_version); - gpx_version = xstrdup(attr.value("version").toString()); + if (gpx_version.isEmpty()) { + gpx_version = attr.value("version").toString(); + } else if ((gpx_version.toInt() * 10) < (attr.value("version").toString().toDouble() * 10)) { + gpx_version = attr.value("version").toString(); } } /* save namespace declarations in case we pass through elements @@ -1456,7 +1456,7 @@ gpx_write_common_position(const Waypoint* waypointp, const gpx_point_type point_ } QString t = waypointp->CreationTimeXML(); writer->writeOptionalTextElement("time", t); - if (gpxpt_track==point_type && 10==gpx_wversion_num) { + if (gpxpt_track==point_type && 10 == gpx_wversion_num) { /* These were accidentally removed from 1.1, and were only a part of trkpts in 1.0 */ if WAYPT_HAS(waypointp, course) { writer->writeTextElement("course", toString(waypointp->course)); @@ -1798,12 +1798,10 @@ gpx_write(void) * available use it, otherwise use the default. */ - if (! gpx_wversion) { - if (! gpx_version) { - gpx_wversion = (char*)"1.0"; - } else { - gpx_wversion = (char*)gpx_version; - } + if (gpx_version.isEmpty()) { + gpx_wversion = (char*)"1.0"; + } else { + gpx_wversion = xstrdup(gpx_version); } if (opt_humminbirdext || opt_garminext) { @@ -1895,10 +1893,7 @@ gpx_free_gpx_global(void) static void gpx_exit(void) { - if (gpx_version) { - xfree(gpx_version); - gpx_version = NULL; - } + gpx_version.clear(); gpx_namespace_attribute.clear(); -- 2.30.2